<?php
include("../user/userlogincheck.php");
include("../include/config.inc.php");

$a=$_REQUEST["a"];
$id=$_REQUEST["id"];
$store_id=$_REQUEST["storeid"];
$createtime=time();

if($id==''){
$id=0;
}

$sql = "select count(*) as count from ".tableprefix."collection where classify='$a' and goods_id='$id' and store_id='$store_id' and userid='$userid'";
$row=$db->fetch_array($db->query($sql));
$count=$row["count"];
if($count>=1){
	if($a=='store'){
		echo "<script>alert('已经关注过了，无需重复关注！');history.back(-1);</script>";
		exit;
	}else{
		echo "<script>alert('你已经收藏过了，无需重复收藏！');history.back(-1);</script>";
		exit;
	}
}

$sql="insert into ".tableprefix."collection(classify,goods_id,store_id,userid,createtime)values('$a','$id','$store_id','$userid','$createtime')";
$db->query($sql);
if(!$db->error()){
		PhpBox('收藏成功！');
		if($a=='goods'){
			GotoPage('../goods.php?id='.$id.'');
		}else{
			GotoPage('../store/index.php?id='.$store_id.'');
		}
	}
	else
	{
		PhpBox('数据库出错！');
		GotoPage('../index.php');
	}
	$db->close();
	exit;
?>